/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.event.ActionEvent
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.Label
 *  javafx.scene.layout.HBox
 *  javafx.scene.layout.Region
 *  javafx.scene.layout.VBox
 *  javafx.stage.Modality
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.index;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.GysApplication;
import com.gys.common.business.FranchiseeUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.LPopup;
import com.gys.common.enums.PopupPos;
import com.gys.common.util.CacheUtil;
import com.gys.controller.BaseController;
import com.gys.controller.LoginController;
import com.gys.controller.index.IndexController;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.example.GetLoginStoreOutData;
import com.gys.data.example.GetUserOutData;
import com.gys.data.franchisee.FranchiseeOutData;
import com.gys.view.LoginView;
import com.gys.view.RestPasswordView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class IndexHeadController
extends BaseController
implements Initializable {
    @FXML
    private HBox head;
    @FXML
    private Button userBtn;
    @FXML
    private Label clientName;
    @FXML
    private Label storeName;
    @FXML
    private VBox userContent;
    @FXML
    private Button restPasswordBtn;
    @Autowired
    private IndexController indexController;
    private LPopup userPopupPane;
    @Autowired
    private LoginController loginController;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;

    @FXML
    public void tongleLeftPane(ActionEvent e) {
        this.indexController.tongleLeftPane();
    }

    public void initialize(URL location, ResourceBundle resources) {
        this.head.getChildren().remove(this.userContent);
        this.userContent.getStyleClass().add("nav-user-popup");
        this.userPopupPane = new LPopup((Region)this.userBtn, PopupPos.down_west);
        this.userPopupPane.setPopupContentPane((Region)this.userContent);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.clientName)) {
            return;
        }
        HttpJson httpJson = FranchiseeUtil.getClientById(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        FranchiseeOutData franchiseeOutData = (FranchiseeOutData)JSON.parseObject((String)httpJson.getMsg(), FranchiseeOutData.class);
        CacheUtil.put("franchisee", franchiseeOutData);
        this.clientName.setText(((FranchiseeOutData)CacheUtil.get("franchisee")).getFrancName());
        this.storeName.setText(((GetLoginStoreOutData)CacheUtil.get("store")).getStoName());
    }

    @FXML
    public void showUserPopup() {
        double width = this.userContent.getPrefWidth();
        if (width < 1.0) {
            width = this.userContent.prefWidth(-1.0);
            width = width < 1.0 ? 200.0 : width;
        }
        this.userPopupPane.show();
    }

    @FXML
    public void restPassword() {
        GysApplication.showView(RestPasswordView.class, (Modality)Modality.APPLICATION_MODAL);
    }

    @FXML
    public void logoutAction() {
        CacheUtil.getCacheManager().getCache("sysCache").flush();
        this.loginController.init();
        GysApplication.showView(LoginView.class);
        this.userPopupPane.hide();
        this.indexController.timer.cancel();
        if (ObjectUtil.isNotEmpty(IndexController.stage)) {
            IndexController.stage.close();
        }
    }

    @FXML
    public void settingBtn(ActionEvent e) {
    }
}

